// import com.alibaba.druid.sql.ast.*;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLFetchStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "../SQLLimit.h"
#include "../SQLName.h"

SQLFetchStatement::SQLFetchStatement()
{
  into = std::make_shared<std::list<SQLExpr_ptr>>();
}
// @Override
void SQLFetchStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLFetchStatement)))
  {
    acceptChild(visitor, cursorName);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLExpr, SQLObject>(into);
    acceptChild(visitor, tmp1);
  }
  visitor->endVisit(SharedObject(SQLFetchStatement));
}

SQLName_ptr SQLFetchStatement::getCursorName()
{
  return cursorName;
}

void SQLFetchStatement::setCursorName(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLFetchStatement));
  }
  this->cursorName = x;
}

SQLLimit_ptr SQLFetchStatement::getLimit()
{
  return limit;
}

void SQLFetchStatement::setLimit(SQLLimit_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLFetchStatement));
  }
  this->limit = x;
}

SQLExpr_list_ptr SQLFetchStatement::getInto()
{
  return into;
}

void SQLFetchStatement::setInto(SQLExpr_list_ptr into)
{
  this->into = into;
}

BOOL_ptr SQLFetchStatement::isBulkCollect()
{
  return bulkCollect;
}

void SQLFetchStatement::setBulkCollect(BOOL_ptr bulkCollect)
{
  this->bulkCollect = bulkCollect;
}

BOOL_ptr SQLFetchStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (cursorName == expr)
  {
    setCursorName(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}
